#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include "MenuScreen.h"
#include "MouseUtility.h"
#include "ResourceManager.h"
#include "SoundManager.h"
#include "Global.h"

float mouseX = 0,mouseY = 0;
bool m_isMusicPause;


#define b_startGame 0
#define b_option 1
#define b_chosen 2
#define b_cursor 3

MenuScreen::MenuScreen(ScreenManager* _screenManager)
	:GameScreen(_screenManager)
{
	if(Global::GetInst()->isMusicOn == true)
		SoundManager::GetInst()->PlaySound("Resource/sound/Pucca.mp3");

	m_screenState = On;
	

#pragma region Create_List_Button

	listButton = vector<Button*>();
	listButton.push_back(new Button("Resource/Image/BT_Play.png", 
		0.3, 0.00, -1.0, 
		0.4, 0.16, 
		0.8, 0.3, 0.5, 1));
	listButton.push_back(new Button("Resource/Image/BT_About.png", 
		0.4, -0.18, -1.0, 
		0.4, 0.16,
		0.5, 0.8, 0.5, 1));
	listButton.push_back(new Button("Resource/Image/BT_Quit.png", 
		0.5, -0.36, -1.0, 
		0.4, 0.16,
		0.5, 0.8, 0.5, 1));

#pragma endregion Create_List_Button

}


MenuScreen::~MenuScreen(void)
{
	listButton.clear();
}


void MenuScreen::Update(float _dt)
{
	m_curSelect = -1;
	for(int i=0; i < listButton.size();i++)
	{
	if(listButton[i]->IsMouseMoving(MouseUtility::GetInst()->getGLMouseX(), MouseUtility::GetInst()->getGLMouseY()))
	{
	m_curSelect = i;
	break;
	}
	}
}

void MenuScreen::Draw()
{
	/// ve background
	
	m_glDraw.GLDrawPlane("Resource/Image/BG_MainMenu.png",
		0, 0, -1.0001,
		(float) 10 / 6, 1, 0,
		1, 1, 1, 1);

	//////////////////////////////////////////////////////////////////////////
	// Ve button
	for(int i=0;i < listButton.size();i++)
	{
		listButton[i]->DrawButton();
	}

}
bool m_isMainGameOn = false;
void MenuScreen::MouseClick(int mouseCode)
{
	switch(mouseCode)
	{
	case 0://left mouse
		
		switch (m_curSelect)
		{
		case 0:
			SoundManager::GetInst()->PauseBgSound("Resource/sound/Pucca.mp3",true);
			if(m_isMainGameOn == false)
			{
				MainScreen* mainScreen;
				mainScreen = new MainScreen(m_screenManager);
				m_screenManager->AddScreen(mainScreen);
				m_screenState = Deactive;
				m_isMainGameOn = true;
			}
			else
			{
				//neu main dang dc chay ngam thi goi lai list
				IScene* scene;
				scene = m_screenManager->screensList[0];
				scene->m_screenState = On;
				m_screenState = Deactive;
			}
			break;
		case 1:
			AboutScreen* optionScreen;
			optionScreen = new AboutScreen(m_screenManager);
			m_screenManager->AddScreen(optionScreen);
			m_screenState = Deactive;
			SoundManager::GetInst()->PlaySound("Resource/sound/SelectButton.mp3");
			break;
		case 2:
			PostQuitMessage(0);
			break;

		default:
			break;
		}
		break;
	case 1: //right mouse
		break;
	default:
		break;
	}
}

void MenuScreen::KeyDown(int keyCode)
{

}

